package com.gpt.article.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.gpt.article.domain.GptGenOutline;
import com.gpt.article.service.IGptGenOutlineService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 文章大纲Controller
 * 
 * @author zhuzi
 * @date 2023-11-26
 */
@RestController
@RequestMapping("/article/outline")
public class GptGenOutlineController extends BaseController
{
    @Autowired
    private IGptGenOutlineService gptGenOutlineService;

    /**
     * 查询文章大纲列表
     */
    @PreAuthorize("@ss.hasPermi('article:outline:list')")
    @GetMapping("/list")
    public TableDataInfo list(GptGenOutline gptGenOutline)
    {
        startPage();
        List<GptGenOutline> list = gptGenOutlineService.selectGptGenOutlineList(gptGenOutline);
        return getDataTable(list);
    }

    /**
     * 导出文章大纲列表
     */
    @PreAuthorize("@ss.hasPermi('article:outline:export')")
    @Log(title = "文章大纲", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, GptGenOutline gptGenOutline)
    {
        List<GptGenOutline> list = gptGenOutlineService.selectGptGenOutlineList(gptGenOutline);
        ExcelUtil<GptGenOutline> util = new ExcelUtil<GptGenOutline>(GptGenOutline.class);
        util.exportExcel(response, list, "文章大纲数据");
    }

    /**
     * 获取文章大纲详细信息
     */
    @PreAuthorize("@ss.hasPermi('article:outline:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(gptGenOutlineService.selectGptGenOutlineById(id));
    }

    /**
     * 新增文章大纲
     */
    @PreAuthorize("@ss.hasPermi('article:outline:add')")
    @Log(title = "文章大纲", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody GptGenOutline gptGenOutline)
    {
        System.out.println(gptGenOutline.getContentOutline());
        return toAjax(gptGenOutlineService.insertGptGenOutline(gptGenOutline));
    }

    /**
     * 修改文章大纲
     */
    @PreAuthorize("@ss.hasPermi('article:outline:edit')")
    @Log(title = "文章大纲", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody GptGenOutline gptGenOutline)
    {
        return toAjax(gptGenOutlineService.updateGptGenOutline(gptGenOutline));
    }

    /**
     * 删除文章大纲
     */
    @PreAuthorize("@ss.hasPermi('article:outline:remove')")
    @Log(title = "文章大纲", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(gptGenOutlineService.deleteGptGenOutlineByIds(ids));
    }
}
